#coding=utf-8
from PIL import Image

def crop(left, top, width, height, dw, dh, imgpath, savepath):
	img = Image.open(imgpath)
	size = img.size
	sw = float(size[0]) / float(width)
	sh = float(size[1]) / float(height)
	left = float(sw) * float(left)
	top = float(sh) * float(top)
	dw = float(sw) * float(dw)
	dh = float(sh) * float(dh)

	print left
	print top
	print dw
	print dh

	fimg = img.crop((int(left), int(top), int(dw+left), int(dh+top)))
	fimg.save(savepath)

def thumbnail(w, h, imgpath, savepath):
	img = Image.open(imgpath)
	img.thumbnail((w, h), Image.ANTIALIAS)
	img.save(savepath)
